﻿/// <Summary> 
/// $Author: Nikhil Chinchwade 
/// This file contains class representing individual graph entity

/// $Creation Date : 
/// </summary>
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MindTree.PerfWorkbench.Azure.Monitor.AzureMonLib;
using Microsoft.Research.DynamicDataDisplay;
using Microsoft.Research.DynamicDataDisplay.DataSources;
using MindTree.PerfWorkbench.Azure.Monitor.AzureMonitor;
using MindTree.PerfWorkbench.Azure.Monitor.Core;
using Microsoft.WindowsAzure.StorageClient;

namespace MindTree.PerfWorkbench.Azure.Monitor
{
   
    /// <summary>
    /// Class representing a GraphEntity
    /// </summary>
    public class GraphEntity : PerfMonResultObserver
    {
        public Dictionary<PerfCounter, GraphSeries> GraphContext = new Dictionary<PerfCounter, GraphSeries>();        

        public GraphEntity()
        {
            PerfResultDataSource.Instance.Subscribe(this);
        }

        /// <summary>
        /// Update graph data
        /// </summary>
        public override void UpdateData()
        {
            int cntr1=0, cntr2=0, cntr3=0;

           /* var exec = from c in PerfResultDataSource.Instance.MonData 
                       where c.Timestamp.
                       select c*/
            foreach (PerfDataRow row in PerfResultDataSource.Instance.MonData)
            {
                cntr1++;
                foreach (KeyValuePair<PerfCounter, GraphSeries> series in GraphContext)
                {
                    if (series.Key.Equals(PerfCounter.GetCounterFromString(row.RoleInstance,row.CounterName)))
                    {
                        cntr2++;
                        PerformanceInfo newInfo = new PerformanceInfo { Time = new DateTime(row.EventTickCount), Value = row.CounterValue };
                        series.Value.PerfData.UpdateDataRow(newInfo);
                        
                        break;
                    }
                }
            }
            cntr3++;
        }
        
        /// <summary>
        /// Destructor
        /// </summary>
        ~GraphEntity()
        {

        }
    }
}
